//
//  LBCCategoryListVC.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LBCCategoryListVC.h"

@interface LBCCategoryListVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *listTableView;
@property (nonatomic, strong)NSMutableArray *listArr;

@end

@implementation LBCCategoryListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
    
    self.listTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _listTableView.delegate = self;
    _listTableView.dataSource = self;
    [self.view addSubview:_listTableView];
    [_listTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.left.mas_equalTo(0);
        
    }];
    _listTableView.rowHeight = SCREEN_HEIGHT / 7.4;
    // 去掉cell的线
    _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [_listTableView registerClass:[LBCCategoryListCell class] forCellReuseIdentifier:@"LBCCategoryListCell"];
    
    _listArr = [NSMutableArray array];
    [self getData];
    
}


- (void)getData{
    
    NSString *urlStr = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/discovery/v1/category/album?calcDimension=hot&categoryId=%ld&device=iPhone&pageId=1&pageSize=20&status=0&tagName=%@", _cateTag.category_id, _cateTag.tname];
    [AFNetworkTool getUrl:urlStr body:nil result:HXJSON headerFile:nil success:^(id result) {
        
        NSMutableArray *array = [result objectForKey:@"list"];
        for (NSMutableDictionary *dic in array) {
            LBCCategoryListModel *cateListM = [LBCCategoryListModel new];
            [cateListM setValuesForKeysWithDictionary:dic];
            [_listArr addObject:cateListM];
        }
        [_listTableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *idntifier = @"LBCCategoryListCell";
    LBCCategoryListCell *cateListCell = [tableView dequeueReusableCellWithIdentifier:idntifier];
    // 显示cell右侧的箭头
    [cateListCell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    
    cateListCell.cateListModel = _listArr[indexPath.row];
    
    return cateListCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    KBAlbumsDetailViewController *albumsVC = [KBAlbumsDetailViewController new];
    LBCCategoryListModel *cateListM = _listArr[indexPath.row];
    albumsVC.albumId = [NSString stringWithFormat:@"%ld", cateListM.albumId];
    [self.navigationController pushViewController:albumsVC animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
